#ifndef __EGL_WRAPPER_H__
#define __EGL_WRAPPER_H__

#pragma once

#include "GLESAdaptor.h"
#include "EGL/egl.h"

namespace Nezha
{

	struct NZ_GLESContext_EGL : public NZ_GLESContext
	{
		EGLContext mEGLContext;
		EGLSurface mEGLSurface;
		EGLDisplay mEGLDisplay;
		EGLConfig mEGLConfig;

		NZ_GLESContext_EGL()
			:mEGLContext(NULL)
			,mEGLSurface(NULL)
			,mEGLDisplay(NULL)
			,mEGLConfig(NULL)
		{
		}
	};

	class EGLAdaptor : public GLESAdaptor
	{
	public:
		EGLAdaptor();
		virtual ~EGLAdaptor();

		virtual void _initialize(NezhaEngine* engine);

		virtual void _uninitialize();

		virtual void releaseContext(NZ_GLESContext* context);

		virtual NZ_GLESContext* createContext();

		virtual void setCurrentContext(NZ_GLESContext* context);

		virtual void clearContext();

		virtual void swapFrameBuffer(bool waitVSync);

		virtual void checkImplError();

	protected:
		EGLConfig* chooseNCreateGLConfig(const int* arrtibs, int* elems);
		EGLConfig* createConfigs(int* num_elems);
		EGLConfig selectGLConfig(const int* minAttribs, const int* maxAttribs);

		NativeDisplayType mNativeDisplay;
		EGLDisplay mGLDisplay;
		EGLNativeWindowType mhWnd;
		EGLContext mMainEGLContext;
		EGLSurface mMainSurface;
		EGLConfig mEGLConfig;
		

		//NZ_GLESContext_EGL mMainContext;
		//NZ_GLESContext_EGL* mCurrentContext;
	};

	NativeDisplayType InternalGetNativeDisplay(EGLNativeWindowType wnd);

}//end namespace Nezha

#endif //end __EGL_WRAPPER_H__